//
//  NewFeatureCollectionViewController.swift
//  SwiftWeibo
//
//  Created by Lucky on 16/5/12.
//  Copyright © 2016年 Lucky. All rights reserved.
//

import UIKit

private let reuseIdentifier = "reuseIdentifier"
private let pageCount = 4

class NewFeatureCollectionViewController: UICollectionViewController {

    private var layout: NewFeatureLayout = NewFeatureLayout()
    
    init () {
        super.init(collectionViewLayout: layout)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        collectionView?.registerClass(NewFeatureCell.self, forCellWithReuseIdentifier: reuseIdentifier)
    }
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
    }
    
    // MARK: - dataSource
    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return pageCount
    }
    
    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! NewFeatureCell
        
        cell.imageIndex = indexPath.item
        
        return cell
    }
    
    // MARK: - delegate
    override func collectionView(collectionView: UICollectionView, didEndDisplayingCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
        let path = collectionView.indexPathsForVisibleItems().last!
        if  path.item == (pageCount - 1) {
            let cell = collectionView.cellForItemAtIndexPath(path) as! NewFeatureCell
            cell.startBtnAnimation()
        }
    }
}
